import os
import re
import time
import locale
def mylistdir(p,f):
    a=os.listdir(p)
    fs=myfind(a,f)
    return(fs)
def myfind(l,p):
    lr=[];
    #print p
    p1=p.replace(".",r"\.")
    p2=p1.replace("*",".*")
    p2=p2+"$"
    for a in l:
        #print a
        if  re.search(p2,a,re.IGNORECASE)==None :
           pass
           #print "pass"
        else:
           lr.append(a)
       #print "append"
    return lr
def filelines(f):
	try:
		return(len(open(f,encoding="utf_8").readlines()))
	except UnicodeDecodeError:
		return(len(open(f).readlines()))
		pass
def main():
	#print(locale.getpreferredencoding())
	lt=time.localtime()
	fn= "filelines"+str(lt[0])+"-"+str(lt[1])+"-"+str(lt[2])+".txt"
	fl=open(fn,"w")
	filetype=["*.cs","*.Designer.cs"]
	nt=[]
	for i in range(len(filetype)):
		nt.append(0)
	for i in range(len(filetype)):
		files=mylistdir(".",filetype[i])
		for f in  files:
			n1=filelines(f)
			fl.write(str(f)+"\t"+str(n1)+"\n")
			nt[i]=nt[i]+n1
		fl.write(filetype[i]+"\t"+str(nt[i])+"\n")
	print(filetype)
	print(nt)
	t=0
	for i in nt:
		t=t+i
	print(t)
	fl.write("*\t"+str(t)+"\n")
	fl.write("-Designer.cs\t"+str(nt[0]-nt[1])+"\n")
	fl.close()
main()